<template>
	<header class="common-header" :class="{isFixed: isFixed ? true : false}">
		<span class="common-header-back" @click="goback"><i class="icon"></i></span>
		<div class="common-header-title slh">{{title}}</div>
	</header>
</template>

<style scoped lang="scss">
	.common-header{
		position: relative;
		height: 44px;
		background: #ffffff;
		padding:0 a(30px);

		&.isFixed{
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 997;
		}
	}
	.common-header-back{
		display: inline-block;
		width: 44px;
		height: 44px;
		padding-top:14px;
		i{@include bg('~__assets/images/icon/back-1.png',24px,16px);}
	}
	.common-header-title{
		text-align:center;
		position: absolute;
		top:0;
		height: 44px;
		line-height: 44px;
		width: a(420px);
		left:50%;
		margin-left: a(-210px);
		font-size: 18px;
		font-weight: bold;
	}
</style>

<script>
	
	export default{
		name:"common-header",
		props:['title','backurl','isFixed'],
		methods:{
			goback(){
				if(this.backurl){
					this.$router.push({path:this.backurl})
				} else{
					if (window.history.length <= 1) {
	                    this.$router.push({path:'/index'})
	                    return false
	                } else {
	                    this.$router.go(-1);
	                    return;
	                }
	                //上面都没执行就说明卡在当前页不是最后一条， histroy记录数量大于1，又没有回退记录，只能返回首页，
	                //如果上面都执行了 页面都跳走了，这个也就不用管了   
	                setTimeout(() => {
	                    this.$router.push({path:'/'})      
	                },500)
				}
			}
		}
	}

</script>